<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/pc/jsp/common/common.jsp"%>
<%@ page import="com.limao.DBDataClass.CrowdSysProjectClass" %>
<%@ page import="com.limao.CacheManager.CrowdSysProjectCache" %>
<%@ page import="com.wsu.search.tools.Tools" %>
<%
 	 String userid=(String)request.getSession().getAttribute("userid");
	 if(CacheClass.getIntValue(userid)==0)
	 {
	 	out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href=document.referrer;</script>"); //后退并刷新
	 } 
    String orderid = request.getParameter("orderid");
    if(CacheClass.isEmpty(orderid))
    {
 		out.println("<script language='JavaScript'>alert('参数不正确！');location.href=document.referrer;</script>"); //后退并刷新
 	}
%>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <title>支付--收货地址</title>
    <link rel="stylesheet" href="js/validation/screen.css" />
    <script src="js/validation/jquery.js"></script>
    <script src="js/validation/jquery.validate.js"></script>
    <script src="js/validation/messages_zh.js"></script>
    <script src="pc/js/jquery.cityselect.js"></script>
    <script>
		$(window).load(function() {
			headertabcurrent=1;
			$("#header").load("pc/header.jsp"); 
			$("#footer").load("pc/footer.jsp"); 
			
			//headerTab(1);
		});
	</script>
</head>
<body  ontouchstart="">
    <div class="theme-popover-mask"></div>
        <!--header-->
	<div  id="header"> </div>

    <div class="container jz bcf" style="margin-top: 18px;">
    
        <div class="w100 of bcf">
            <div class="fqzcTittle jz of clearfix">
                <div class="fl f20 c3">
                    收货地址<span class="f16 c9" style="margin-left: 20px">（必须填写真实有效资料）</span>
                </div>

            </div><!--fqzcTittle-->
            <div class="w100 of">
            <form  method="post" id="signupForm" action="" >
                <div class="ishenqing jz of">
                   
                    <div class="zcDiv clearfix">
                        <label for="city_3" class="IDcard f18 fl"><img src="pc/images/xing.png" class="xing dib pr">所在地</label>
                        <div id="city_3" class="fr">
                            <div class="w100 clearfix pr">
                                <div class="fl f16">
                                    <select class="prov" id="prov"  name="prov" required="required"></select>&nbsp;(省份)
                                </div>
                                <div class="fr f16" style="margin-left: 38px">
                                    <select class="city" id="city" name="city" disabled="disabled" required="required"></select>&nbsp;(城市)
                                </div>
                            </div>
                        </div> <!--city_3-->
                        <script>
                            $(function () {
                                $("#city_3").citySelect({required: false});
                            })
							
                        </script>
                    </div>
                    <div class="pr">
	                    <div class="zcDiv clearfix of">
	                        <textarea id="detailAddress" name="detailAddress" class="zcInput fr" placeholder="详细地址" style="min-height: 110px;padding-top: 10px;padding-bottom: 10px;"></textarea>
	                    </div>
                    </div>
					<div class="pr">
						<div class="zcDiv clearfix of pr">
	                        <label for="user_name" class="IDcard f18 fl"><img src="pc/images/xing.png" class="xing dib pr">联系人</label>
	                        <input type="text" name="user_name" id="user_name"  class="zcInput fr" placeholder="真实姓名"/>
	                    </div>
					</div>
                    <div class="pr">
	                     <div class="zcDiv clearfix of pr">
	                        <label for="usertel" class="IDcard f18 fl"><img src="pc/images/xing.png" class="xing dib pr">联系电话</label>
	                        <input type="text" name="usertel" id="usertel" class="zcInput fr" placeholder="联系电话"/>
	                    </div>
                    </div>
                   
                </div><!--ishenqing-->
                </form>
            </div>
            
                   <div class="w100 dashLine" style="margin-top: 8px;margin-bottom: 15px;"></div>
                     
                    <div class="zcDiv w100">
                        <input type="button" onclick="sendGoods();" name="" id="" value="确认" style="margin-top: 130px;" class="fqztSub blueh cursor db jz cf tc f20">
                    </div>
        </div>
        
    </div><!--container-->

	<!--footer-->
    <div id="footer" class="footer w100 of"></div>
    
    <div class="theme-popover-mask"></div>
  <!--  <div id="successSub" class="w100 h100 pf">
       <div class="jz of bcf">
            <div class="sqtittle tc jz c3">
                申请提交成功
            </div>
           <p class="successSubP f18 t2">
               您的认证申请已经提交，工作人员在三个工作日对资料进行审核，期间
               请保持通讯顺畅。
           </p>
           <button class="successSubBtn cf tc jz db blueh" onclick="successSubHide();">关闭</button>
       </div>
   </div> --><!--successSub-->

</body>
<script>
var myValidator;

// 联系电话(手机/电话皆可)验证 
jQuery.validator.addMethod("isPhone", function(value,element) { 
  var length = value.length; 
  var mobileTel = /^((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/; 
  var tel = /^\d{3,4}-?\d{7,9}$/; 
  return this.optional(element) || mobileTel.test(value); 

}, "请正确填写您的联系电话"); 


$().ready(function() {
	 	  myValidator=$("#signupForm").validate(
	 		{
	 			rules:{
  	 				prov: {
                		required:true,
                		isShengcity:true
            		},			
  	 				city: {
                		required:true,
                		isShengcity:true
            		},
            		detailAddress:{
            			required:true,
             			rangelength:[5,50] 
            		},
            		user_name:
            		{
            			required:true,
            			rangelength:[2,15]
            		},
            		usertel:
            		{
            			required:true,
            			digits:true,
            			isPhone: true 
	 				}
	 			},
	 			//errorElement: 'p',
                errorPlacement: function(error, element) {
                // Append error within linked label
                
                $( element )
	                .closest( "form" )
	                .find( element )
	                .parent("div")
	                .after( error );
                },
                errorElement: "p"
				
	 		});
	 		
        //取上次的收货地址
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 146}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
                console.log(data);
                if (data.state == 1) {
                    // 申请成功 关闭页面 回退
                    if (typeof(data.obj.address) != "undefined") {
                        // 设置默认地址
                        $.getJSON("pc/js/city.min.js", function (json) {
                            $.each(json.citylist, function (i, prov) {
                                if (prov.p.indexOf(data.obj.shengid) != -1) {
                                    $.each(prov.c, function (i, city) {
                                        if (city.n.indexOf(data.obj.cityid) != -1) {
                                            $("#city_3").citySelect({prov: prov.p, city: city.n, required: false});

                                            // 填写详细地址
                                            var sc = prov.p.split('_')[0] + city.n.split('_')[0];
                                            $("#detailAddress").val(data.obj.address.substring(sc.length, data.obj.address.length));
                                        	$("#user_name").val(data.obj.person_name);
                                        	$("#usertel").val(data.obj.tel);
                                        	
                                        	return true;
                                        }
                                    });
                                    return true;
                                }
                            });
                        });
                    }

                } else {
                    // 其他错误弹出提示
                    layer.alert(data.info);
                }
            },
            error: function (data) {
                layer.alert(data.info);
            },
            complete: function () {
            }
        });
    
});



  var orderidKind="<%=orderid%>";
    var orderidVal = orderidKind.split("_")[0];
     var Kind = orderidKind.split("_")[1];
	  var m = "";
		if(Kind == "shengwang"){
		  m = 1666;
		}
		if(Kind == "huigou"){
		  m = 1676;
		}
 
 
  // 发货
	function sendGoods(){
	       if(myValidator.form()== false){
	            layer.alert("填写存在错误 ！");
	            return false;
	        }
            
	        var provVal =$.trim($(".prov").find("option:selected").val());
	        var cityVal =$.trim($(".city").find("option:selected").val());
	        var detailAddress = $.trim($('#detailAddress').val());
	        var usernameVal =$.trim($('#user_name').val());
	        var usertelVal = $.trim($('#usertel').val());
	        var address=provVal.split("_")[0]+cityVal.split("_")[0]+detailAddress+"_"+usernameVal+"_"+usertelVal;
	        
	        
	         //按要求过滤
            if(detailAddress.indexOf("_")>-1){
            	 layer.alert("您的详细地址中存在干扰字符，例如（下划线）！");
               	return false;
            }
			
			console.log(m+" : "+orderidVal+" : "+address);
			
			
		$.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m:m,orderid:orderidVal,address:address}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
               if (data.state == 1) {
                  // 成功弹出提示
                  layer.alert(data.info);
                  setTimeout('window.history.back()', 1600); 
                } else {
                    // 其他错误弹出提示
                   layer.alert(data.info);
                }
            },
            error: function (data) {
                layer.alert(data.info);
            },
            complete: function () {
            }
        });

      
        
	}

</script>

</html>